package vworld.business.admin;

import generated.business.admin.AdminServicePOA;
import generated.callback.ClientCallback;
import generated.domain.avatar.Avatar;
import generated.domain.user.User;
import generated.domain.world.World;

import java.util.Map;

import org.omg.CORBA.ORB;

import vworld.ServerSingleton;

public class AdminServiceServant extends AdminServicePOA {

	private ORB orb;

	public void setOrb(ORB pOrb) {
		orb = pOrb;
	}

	public void kickAvatar(Avatar avatarToKick) {
		for (Map.Entry<String, ClientCallback> e : ServerSingleton
				.getInstance().REGISTERED_CLIENT_MAP.entrySet()) {
			if (avatarToKick.getName().equals(e.getValue().avatarName())) {
				
				
				
				System.out.println("########## key : "+e.getKey());
				System.out.println("########## login : "+e.getValue().userLogin());
				System.out.println("########## role : "+e.getValue().userRole());
				System.out.println("########## avatar name : "+e.getValue().avatarName());
				System.out.println("########## room name : "+e.getValue().roomName());
				
				
				ServerSingleton.getInstance().roomImpl.exitRoom(e.getValue(),
						avatarToKick, e.getValue().roomName());
				
				
				System.out.println("&&&&&&&&& key : "+e.getKey());
				System.out.println("&&&&&&&&& login : "+e.getValue().userLogin());
				System.out.println("&&&&&&&&& role : "+e.getValue().userRole());
				System.out.println("&&&&&&&&& avatar name : "+e.getValue().avatarName());
				System.out.println("&&&&&&&&& room name : "+e.getValue().roomName());
				
				
				e.getValue().doNotifyOnAvatarKick();
				
				
				break;
			}
		}
	}

	public void kickUser(User userToKick) {
		for (Map.Entry<String, ClientCallback> e : ServerSingleton
				.getInstance().REGISTERED_CLIENT_MAP.entrySet()) {
			if (userToKick.getLogin().equals(e.getValue().userLogin())) {
				ServerSingleton.getInstance().connectionImpl.logout(e
						.getValue());
				e.getValue().doNotifyOnUserKick();
				break;
			}
		}
	}

	public World createWorld() {
		// TODO Auto-generated method stub
		return null;
	}
}
